home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1999 March / EnigmA AMIGA RUN 35 (1999)(G.R. Edizioni)(IT)[!][issue 1999-03].iso / earcd / utils / xad / developer / sources / exampleclient.c
C/C++ Source or Header  |  1999-01-01  |  6KB  |  174 lines

  1. #ifndef XADMASTER_EXAMPLE_C
  2. #define XADMASTER_EXAMPLE_C
  3.  
  4. /* Programmheader
  5.  
  6.     Name:        Example.c
  7.     Main:        xadmaster
  8.     Versionstring:    $VER: Example.c 1.0 (16.02.1999)
  9.     Author:        SDI
  10.     Distribution:    Freeware
  11.     Description:    Example disk archiver client
  12.  
  13.  1.0   16.02.99 : first version
  14. */
  15.  
  16. #include <proto/xadmaster.h>
  17. #include <dos/dos.h>
  18. #include "SDI_compiler.h"
  19. #include "xpkstuff.c"
  20.  
  21. #ifndef XADMASTERFILE
  22. #define Example_Client        FirstClient
  23. #define NEXTCLIENT        0
  24. UBYTE version[] = "$VER: Example 1.0 (16.02.1999)";
  25. #endif
  26. #define EXAMPLE_VERSION        1
  27. #define EXAMPLE_REVISION    1
  28.  
  29. /* This is an empty example client! You should replace all "EXAMPLE"
  30. texts with text related to your own client. */
  31.  
  32. /* NOTE: I normally use SAS-C. This compiler supports local base variables
  33. for library calls, so all functions accessing exec function have a line like:
  34.  
  35.   struct ExecBase * SysBase = xadMasterBase->xmb_SysBase;
  36.  
  37. If your compiler does not support that, insert a global base and assign it
  38. in Example_GetInfo() function:
  39.  
  40.   SysBase = xadMasterBase->xmb_SysBase;
  41.  
  42. This method is better than using address 4 (ExecBase-Pointer) directly.
  43.  
  44. Also a global version of xadMasterBase is needed. Rename the argument of the
  45. functions to lower case xadmasterbase and add following line in
  46. Example_GetInfo() function:
  47.  
  48.   xadMasterBase = xadmasterbase;
  49.  
  50. xadMasterBase also has a pointer to DOSBase, but normally this should not
  51. be necessary, but it is useful for debug output in test versions.
  52. */
  53.  
  54. /* See the included example clients as well! */
  55.  
  56. ASM(BOOL) Example_RecogData(REG(d0, ULONG size), REG(a0, STRPTR data),
  57. REG(a6, struct xadMasterBase *xadMasterBase))
  58. {
  59.   if(/* do some checks here (headerID, header checksum, ...) */)
  60.     return 1; /* known file */
  61.   else
  62.     return 0; /* unknown file */
  63. }
  64.  
  65. ASM(LONG) Example_GetInfo(REG(a0, struct xadArchiveInfo *ai),
  66. REG(a6, struct xadMasterBase *xadMasterBase))
  67. {
  68.   /* return an error code, as long as function is empty */
  69.   return XADERR_NOTSUPPORTED;
  70.  
  71.   /* Always do this function first (after RecogData). Normally it's the
  72.   easiest one.
  73.   General style for file archivers:
  74.   -Allocate "xadAllocObject(XADOBJ_FILEINFO, ...., TAG_DONE)" the
  75.    xadFileInfo structure for every file and fill it's fields with
  76.    correct values (date, size, protection, crunched size, flags, ...).
  77.   -Add the allocated structure to a linked list, which is assigned to
  78.    ai->xai_FileInfo.
  79.   -If an error occurs set "ai->xai_Flags & XADAIF_FILECORRUPT" or
  80.    return the error if it is really serious. If there are already valid
  81.    entries in linked list, there cannot be that serious!
  82.   -Leave this function.
  83.   General style for disk archivers:
  84.   -Allocate "xadAllocObject(XADOBJ_DISKINFO, ...., TAG_DONE)" the
  85.    xadDiskInfo structure for every file and fill it's fields with
  86.    correct values (tracks, heads, flags, ...).
  87.   -Add the allocated structure to a linked list, which is assigned to
  88.    ai->xai_DiskInfo.
  89.   -If there are information texts, create a linked list with xadTextInfo
  90.    structures. These are allocated with xadAllocObjectA(XADOBJ_TEXTINFO, 0).
  91.   -If an error occurs set "ai->xai_Flags & XADAIF_FILECORRUPT" or
  92.    return the error if it is really serious. If there are already valid
  93.    entries in linked list, there cannot be that serious!
  94.   -Leave this function.
  95.  
  96.   For nearly all archivers it is necessary to store current file position
  97.   (ai->xai_InPos), to be able to find the data in unarchive function.
  98.  
  99.   Get data using "xadHookAccess(XADAC_READ, size, buf, ai)" and seek input
  100.   data using "xadHookAccess(XADAC_INPUTSEEK, size, 0, ai)".
  101.   */
  102.  
  103.   return 0;
  104. }
  105.  
  106. ASM(LONG) Example_UnArchive(REG(a0, struct xadArchiveInfo *ai),
  107. REG(a6, struct xadMasterBase *xadMasterBase))
  108. {
  109.   /* return an error code, as long as function is empty */
  110.   return XADERR_NOTSUPPORTED;
  111.  
  112.   /*
  113.   -Either use ai->xai_CurDisk or ai->xai_CurFile and seek the input data
  114.    to the position required to access the archived data for the wanted entry:
  115.    "xadHookAccess(XADAC_INPUTSEEK, pos-ai->xai_InPos, 0, ai)".
  116.   -Extract the data using XADAC_READ for reads, XADAC_WRITE for storing data
  117.    or XADAC_COPY for copying the data directly.
  118.   - Leave the function either returning 0 or an errorcode, which occured.
  119.   */ 
  120. }
  121.  
  122. ASM(void) Example_Free(REG(a0, struct xadArchiveInfo *ai),
  123. REG(a6, struct xadMasterBase *xadMasterBase))
  124. {
  125.   /* This function needs to free all the stuff allocated in info or
  126.   unarchive function. It may be called multiple times, so clear freed
  127.   entries!
  128.   */
  129.  
  130.   /* The following example frees file and disk archive data. It assumes,
  131.   that disk archive information texts are allocated using AllocVec and all
  132.   the other stuff (file names, comments, ...) is allocated using the tags
  133.   of xadAllocObject function.
  134.   You should modify that function to meet your special requirements.
  135.   */
  136.  
  137.   struct ExecBase * SysBase = xadMasterBase->xmb_SysBase;
  138.   struct xadFileInfo *fi, *fi2;
  139.   struct xadDiskInfo *di, *di2;
  140.   struct xadTextInfo *ti, *ti2;
  141.  
  142.   for(fi = ai->xai_FileInfo; fi; fi = fi2)
  143.   {
  144.     fi2 = fi->xfi_Next;
  145.     xadFreeObjectA(fi, 0);
  146.   }
  147.   ai->xai_FileInfo = 0;
  148.  
  149.   for(di = ai->xai_DiskInfo; di; di = di2)
  150.   {
  151.     di2 = di->xdi_Next;
  152.     
  153.     for(ti = di->xdi_TextInfo; ti; ti = ti2)
  154.     {
  155.       ti2 = ti->xti_Next;
  156.       if(ti->xti_Text)
  157.         FreeVec(ti->xti_Text);
  158.       xadFreeObjectA(ti, 0);
  159.     }
  160.     xadFreeObjectA(di, 0);
  161.   }
  162.   ai->xai_DiskInfo = 0;
  163. }
  164.  
  165. struct xadClient Example_Client = {
  166. NEXTCLIENT, XADCLIENT_VERSION, 1, EXAMPLE_VERSION, EXAMPLE_REVISION,
  167. /* Here the size the client really needs to detect the filetype must be
  168. inserted */, /* XADCF_DISKARCHIVER and/or XADCF_FILEARCHIVER */,
  169. 0 /* Type identifier. Normally should be zero */, "Example",
  170. (BOOL (*)()) Example_RecogData, (LONG (*)()) Example_GetInfo,
  171. (LONG (*)()) Example_UnArchive, (void (*)()) Example_Free};
  172.  
  173. #endif /* XADASTER_EXAMPLE_C */
  174.